<template>
  <!-- 弹出框 -->
  <el-dialog v-model="dialogVisible">
    <el-divider border-style="double" />
    <el-form :model="serviceRel">
      <el-form-item label="选择服务">
        <el-select v-model="serviceRel.exhServiceId" placeholder="--请选择--">
          <el-option :label="item.name" v-for="item in serviceList" :key="item.id" :value="item.id" />
        </el-select>
      </el-form-item>
      <el-form-item label="服务描述">
        <el-input v-model="serviceRel.introduce" autocomplete="off" type="textarea" />
      </el-form-item>
    </el-form>
    <el-divider border-style="double" />
    <template #footer>
      <span class="dialog-footer">
        <el-button type="primary" @click="save">保存</el-button>
      </span>
    </template>
  </el-dialog>
</template>

<script setup lang="ts">
import { reactive, ref, defineExpose, defineProps, defineEmits, onMounted } from "vue";
import { getServiceList, saveServiceRel } from "@/api/api";
interface service {
  id: string;
  name: string;
}
const props = defineProps({ exhId: String });
const emit = defineEmits(["updateServiceRelList"]);
const dialogVisible = ref(false);
const serviceRel = reactive({
  exhId: "" as string | undefined,
  exhServiceId: "",
  introduce: ""
});
const serviceList = ref([] as service[]);
const getList = async () => {
  serviceList.value = await getServiceList();
};
const save = async () => {
  serviceRel.exhId = props.exhId;
  let res = await saveServiceRel(serviceRel);
  if (res === true) {
    dialogVisible.value = false;
    serviceRel.exhServiceId = "";
    serviceRel.introduce = "";
    emit("updateServiceRelList");
  }
};
defineExpose({
  dialogVisible
});
onMounted(getList);
</script>
<style scoped></style>
